package om.jenkinslog;

import om.Utils.EsClientUtils;

import javax.lang.model.element.VariableElement;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;

/**
 * @author xiazhonghai
 * @date 2021/1/19 15:41
 * @description:
 */
public class Main {
    public static final String hosturl="_host";
    static Properties conf = new Properties();
    static {
        InputStream resourceAsStream = JenkinsLog.class.getClassLoader().getResourceAsStream("config.properties");
        try {
            conf.load(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            resourceAsStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void main(String[] args) throws IOException, InterruptedException {
//        String communitys=args[0];
        String communitys="openeuler";
        try {
            String[] community = communitys.split(",");
            List<String> communitylist = Arrays.asList(community);
            List<Thread> threads=new ArrayList<Thread>();
            for (int i = 0; i < communitylist.size(); i++) {
                String urls = conf.getProperty(communitylist.get(i) + hosturl);
                String[] url = urls.split(",");
                for (String u : url) {
                    JenkinsLog jenkinsLog = new JenkinsLog();
                    jenkinsLog.setCom(communitylist.get(i));
                    jenkinsLog.setBaseurl(u);
                    jenkinsLog.setConf(conf);
                    Thread thread = new Thread(jenkinsLog);
                    threads.add(thread);
                    thread.start();
                }
            }
            for (Thread thread : threads) {
                thread.join();
            }
            for (int i = 0; i < communitylist.size(); i++) {
                JenkinsLog jenkinsLog = new JenkinsLog();
                jenkinsLog.setCom(communitylist.get(i));
                jenkinsLog.setConf(conf);
                jenkinsLog.updateTotal();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ArrayList<Thread> threads=new ArrayList<>();
        for (int i = 1; i <= 8; i++) {

            TestLog testLog = new TestLog(conf.getProperty("openQahost"), "/group_overview/"+i,conf.getProperty("openQacommunity"));
           Thread t= new Thread(testLog);
           t.start();
            threads.add(t);
        }
        for (Thread thread : threads) {
            thread.join();
        }
        Common.httpclient.close();
    }
}
